<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of GlassPublicAction
 *
 * @author zhuang
 */
class GlassPublicAction extends BasicCommonAction {
    
    public $_default_post=array('query'=>array('to_hide'=>1));

    //put your code here
    public function index() {
        ///获取当前Action名称
        $name = $this->getActionName();
        if ($this->_view_model === true) {
            $name = $name . 'View';
        }
        ///获取当前模型
        $model = D($name);
        ///条件
        $opert = array('where' => _search($this->_default_where, $this->_default_post), 'sortBy' => $this->_sortBy);
        $opert['where'] .= $this->_getKeyWhere();
        ///格式化+获取列表信息   
///		$list	=	$this->_listAndFormat(&$model,$opert);	  
        $_formatListKey = ACTION_NAME . '_' . MODULE_NAME;
//       echo '<pre>';print_r($this->_listAndFormat(&$model, $opert, $_formatListKey));exit;
        ///assign
        $this->assign('list', $this->_listAndFormat(&$model, $opert, $_formatListKey));
        ///display
        $this->displayIndex();
    }
    
    public function _getKeyWhere(){
        $key    = $_POST['key'];
        if(empty($key)){
            return '';
        }
        $arr    = array(
            'user_name','sex','instock_date',
            'age',
            'job',
            'telphone',
            'qiu_right','zhu_right','zhou_right','tong_right','jiao_right','luo_right',
            'qiu_left','zhu_left','zhou_left','tong_left','jiao_left','luo_left',
            'address',
            'comments',
        );
        $where  = ' and ( 1<>1 ';
        foreach($arr as $val){
            $where .= " or ".$val." like '%".$key."%'";
        }
        $where  .= ")";
        return $where;
    }
    public function edit() {
		///自动补上编号
    	$this->_autoMaxNo();
		///获取当前Action名称
	 	$name = $this->getActionName();
 		///获取当前模型
		$model 	= D($name);   
		///模型ID
		$id 	= 	intval($_REQUEST[$model->getPk()]);  
		if ($id>0) {
			if (method_exists($model,'getInfo')) {
				$vo = _formatArray($model->getInfo($id),$this->_default_format);  
			}else{
				$vo = _formatArray($model->getById($id),$this->_default_format);  
			}
			///如果查询结果是空提示错误 
			if (!is_array($vo)) {
				exit(L('data_right_error'));
			} 
			$this->rs	=	$vo; 
			$model->cacheLockVersion($vo);
		}else {
			$this->error(L('_ERROR_'));
		}
		$this->display (); 
	}  
}

?>
